package com.yfp.minapp.auth.api.factory;


import cn.hutool.core.date.DateTime;
import com.yfp.common.core.domain.Response;
import com.yfp.minapp.auth.api.RemoteClientService;
import com.yfp.minapp.auth.api.domain.Client;
import com.yfp.minapp.auth.api.domain.ReplenishDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


/**
 * Client 服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteClientFallbackFactory implements FallbackFactory<RemoteClientService> {


    private static final Logger log = LoggerFactory.getLogger(RemoteClientFallbackFactory.class);

    @Override
    public RemoteClientService create(Throwable throwable) {
        log.error("Client 服务调用失败:{}", throwable.getMessage());
        return new RemoteClientService() {

            @Override
            public Response<Boolean> adminRefund(String orderListId, BigDecimal amt) {
                log.error("调用{}异常:{}", "adminRefund", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Boolean> adminBalanceRefund(String orderListId, BigDecimal amt) {
                log.error("调用{}异常:{}", "adminBalanceRefund", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Boolean> adminRefundNotifyResultSimulate(String orderListId, BigDecimal amt) {
                log.error("调用{}异常:{}", "adminRefundNotifyResultSimulate", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<List<Client>> clientList() {
                log.error("调用{}异常:{}", "clientList", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Void> checkAllOrderExpired() {
                log.error("调用{}异常:{}", "checkAllOrderExpired", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Map<String, ReplenishDTO.Marketing>> computeEstimatedPrice(String machineId, List<ReplenishDTO> replenishVos) {
                log.error("调用{}异常:{}", "computeEstimatedPrice", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Void> notifyCookingStatus(String orderId, String orderDetailId) {
                log.error("调用{}异常:{}", "notifyCookingStatus", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Void> notifyTakeFood(String orderId, String orderDetailId, DateTime date) {
                log.error("调用{}异常:{}", "notifyTakeFood", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Boolean> storedRefund(String clientId) {
                log.error("调用{}异常:{}", "storedRefund", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Boolean> mallOrderRefund(Long id) {
                log.error("调用{}异常:{}", "mallOrderRefund", throwable.getMessage());
                return Response.failuer();
            }

            @Override
            public Response<Void> updateOrderLogisticsInfoJob() {
                log.error("调用{}异常:{}", "updateOrderLogisticsInfoJob", throwable.getMessage());
                return Response.failuer();
            }
        };
    }

}
